// development_deck_test.cc

#include "development_deck.h"

using namespace std;
class DevelopmentDeckTest {
 public:
  DevelopmentDeckTest() {};

  ~DevelopmentDeckTest() {};
  
  bool RunTests() {
    printf("Running tests:\n");
    SetUp();
    TestConstruction();
    BreakDown();

    printf("Running tests:\n");
    SetUp();
    TestEmptyingDeck();
    BreakDown();
    printf("All tests passed.\n");

  };
  
 private:

  void SetUp() {
    deck_ = new DevelopmentDeck();
  };
  void BreakDown() {
    delete deck_;
  };
  
  void TestConstruction() {
    printf("  Testing the constructor.\n");
    assert(deck_ != NULL);
    assert(!deck_->Empty());
    assert(deck_->Size() == 25);
  };

  void TestEmptyingDeck() {
    printf("  Testing emptying deck.\n");
    assert(deck_ != NULL);
    assert(!deck_->Empty());
    int cards[DevelopmentDeck::kNumDevTypes];
    memset(cards, 0, sizeof(cards));
    int cards_left = 25;
    for (int i = 0; i < 50; i++) {
      int j = deck_->GetCard();
      printf("    Picked a  %s\n", DevelopmentDeck::CardName(j).c_str());
      if (DevelopmentDeck::IsValid(j)) {
	cards_left -= 1;
	cards[j]++;
      }
      assert(deck_->Size() == cards_left);
    }
    assert(deck_->Empty());
    for (int i = 0; i < DevelopmentDeck::kNumDevTypes; i++) {
      assert(cards[i] == DevelopmentDeck::NumCardsOfType(i));
    }
  };

  DevelopmentDeck *deck_;
};


int main(int argc, char *argv[]) {

  DevelopmentDeckTest test;
  test.RunTests();
}

